/*****
I do the following dofile to recover points coordinates to be merged with Proof2R.dta 
Ideally we would like to keep coordinates in the original dofile that creates Proof2R.dta 
	* DATASETS Used:
		Modified:
			- NAPP/MolaModified_NAPP_JAG4new.dta comes from A_CREATING_SAMPLE\MolaNAPP16v3.do
			- NAPP/Proof2Rnew.dta comes from \C_ANALYSIS/border_reg_weighted4v1.do
			- "$NAPP/Proof2RPlacebonew.dta" comes from \C_ANALYSIS/border_reg_weighted4Placebov1.do
		
	* DATASETS Created:
		- "$NAPP/PointsCoordinatesnew.dta"
		- "$NAPP/Proof2RCoordnew.dta"
		- "$NAPP/Proof2RPlaceboCoordnew.dta"
****/
gl NAPP "/Users/`c(username)'/Dropbox/NetworkParish2016/Occupational_Choice/Submission/Final_ReStat/Codes/NAPP"
*gl ROOT "C:/Users/ja.guerra/Dropbox"
*gl NAPP "$ROOT/NetworkParish2016/Occupational_Choice/Data/NAPP_address"

use "$NAPP/MolaModified_NAPP_JAG4new.dta", clear
keep objectid_1 longitude latitude
duplicates drop objectid_1, force
save "$NAPP/PointsCoordinatesnew.dta", replace

merge 1:n objectid_1 using "$NAPP/Proof2Rnew.dta", gen(mergecoord)

drop if mergecoord~=3
saveold  "$NAPP/Proof2RCoordnew.dta", replace version(12)

use "$NAPP/PointsCoordinatesnew.dta", clear
merge 1:n objectid_1 using "$NAPP/Proof2RPlacebonew.dta", gen(mergecoord)
drop if mergecoord~=3
rename civil civilplacebo
rename social socialplacebo

merge 1:1 HHNUMhead using "$NAPP/Proof2Rnew.dta", keepusing(civil social)
rename social socialorig
rename civil civilorig
rename civilplacebo civil 
rename socialplacebo social 
keep if _merge==3

saveold "$NAPP/Proof2RPlaceboCoordnew.dta", replace version(12)
